import { Controller } from "../../mvc/core/Controller";
import { IGuideWelcomeModule } from "../../../modules/interfaces/IGuideWelcomeModule";
import { WindowEvent } from "../../component/window/WindowEvent";
import { Global } from "../../../com/gengine/global/Global";
import { Game } from "../Game";
import { SceneEvent } from "../scene/events/SceneEvent";
import { Dispatcher } from "../../mvc/core/Dispatcher";
import { DataEvent } from "../events/DataEvent";
import { EventName } from "../mvc/EventName";
import { IView } from "../../mvc/interfaces/IView";
import { GuideWelcomeModule } from "../../../modules/GuideWelcomeModule";
import { LayerManager } from "../manager/LayerManager";
//class GuideWelcomeController
    
    export  class GuideWelcomeController extends Controller
    {
       

        public stageResize(): void
        {
            if (_view && !_view.isHide) 
            {
                (_view as IGuideWelcomeModule).stageResize();
            }
            return;
        }

        /* internal  */onWindowShow(arg1: WindowEvent): void
        {
            Global.stage.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onStageMouseDownkHandler, false, 9999);
            if (Game.isSceneInit()) 
            {
                Game.scene.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onSceneMouseDownHandler, false, 9999, true);
            }
            else 
            {
                Game.scene.addEventListener(SceneEvent.INIT, this.onSceneInitHandler);
            }
            return;
        }

        /* internal  */onWindowClose(arg1: WindowEvent): void
        {
            Game.scene.removeEventListener(SceneEvent.INIT, this.onSceneInitHandler);
            Game.scene.removeEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onSceneMouseDownHandler);
            Global.stage.removeEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onStageMouseDownkHandler);
            Dispatcher.dispatchEvent(new DataEvent(EventName.Guide_BeginGame, true));
            return;
        }

        /* internal  */onStageMouseDownkHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            _view.hide();
            if (arg1) 
            {
                arg1.stopImmediatePropagation();
            }
            return;
        }

        /* internal  */onSceneMouseDownHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            arg1.stopImmediatePropagation();
            this.onStageMouseDownkHandler(null);
            return;
        }

        /* internal  */onSceneInitHandler(arg1: SceneEvent): void
        {
            Game.scene.addEventListener(flash.events.MouseEvent.MOUSE_DOWN, this.onSceneMouseDownHandler, false, 9999, true);
            return;
        }

        protected /* override */ initView(): IView
        {
            var loc1=new GuideWelcomeModule();
            loc1.addEventListener(WindowEvent.SHOW, this.onWindowShow);
            loc1.addEventListener(WindowEvent.CLOSE, this.onWindowClose);
            loc1.layer = LayerManager.guideLayer;
            return loc1;
        }
    }
